package cate.game.role.bag.newtalent;


import cate.common.table.fight.skill.row.SkillBaseRow;
import cate.common.table.item.hero.row.HeroTalentRow;
import cate.common.table.res.hero.back.row.InheritTalenRow;
import cate.game.play.support.PlayBuildContext;
import cate.game.util.GameKit;
import com.fasterxml.jackson.annotation.JsonIgnore;
import cp.solution.pattern.ICopiable;
import easy.java.dev.note.NoteField;

public class TalentItem implements ICopiable<TalentItem> {

    @NoteField("模板ID")
    public int tid;

    @NoteField("位置")
    public int pos;

    public TalentItem() {}

    public TalentItem(int tid, int pos) {
        this.tid = tid;
        this.pos = pos;
        this.uid = GameKit.uid();
    }

    @NoteField("唯一ID")
    public String uid;

    @JsonIgnore
    public HeroTalentRow getTpl(PlayBuildContext ctx) {
        HeroTalentRow row = ctx.runeExcel().talent.get(tid);
        if (row == null) {
            return row;
        }
        SkillBaseRow skillBaseRow = ctx.skillExcel().base.get(row.skillId);
        if (skillBaseRow != null) {
            row.protoId = skillBaseRow.protoId;
        } else {
            row.protoId = row.skillId;
        }
        return row;
    }

    @JsonIgnore
    public InheritTalenRow getInheritTpl(PlayBuildContext ctx){
        InheritTalenRow row = ctx.heroBackExcel().inherit.get(this.tid);
        if (row == null) {
            return row;
        }
        SkillBaseRow skillBaseRow = ctx.skillExcel().base.get(row.skillId);
        if (skillBaseRow != null) {
            row.protoId = skillBaseRow.protoId;
        } else {
            row.protoId = row.skillId;
        }
        return row;
    }

    @Override
    public TalentItem copy() {
        TalentItem cp = new TalentItem();
        cp.tid = this.tid;
        cp.uid = this.uid;
        cp.pos = this.pos;
        return cp;
    }
}
